﻿using System;
using Cysharp.Threading.Tasks;
using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;

namespace JQMergeFramework
{
    public enum BuildTipsType
    {
        BuildFinish,
        ScoreFinish,
    }

    public class UIAddLvTips: MonoBehaviour
    {
        public ParticleSystem fireworksL, fireworksR;

        public GameObject scoreFinishTipsTran;
        public GameObject buildFinishTipsTran;
        
        public Transform scoreFinishBg;
        
        public Transform buildFinishBg;
        
        public Text buildFinishNumTxt;
        
        private Vector3 defaultScoreBgPos;

        public Transform buildIcon;
        
        private void Awake()
        {
            defaultScoreBgPos = scoreFinishBg.localPosition;
        }

        public void Open(BuildTipsType type)
        {

            switch (type)
            {
               case BuildTipsType.ScoreFinish:
                   ShowScoreFinish();
                   break;
               case BuildTipsType.BuildFinish:
                   ShowBuildFinish();
                   break;
            }
        }

        void ShowScoreFinish()
        {
            this.scoreFinishTipsTran.SetActive(true);
            this.buildFinishTipsTran.SetActive(false);
            fireworksL.Play();
            fireworksR.Play();
            
            scoreFinishBg.DOKill();
            scoreFinishBg.gameObject.SetActive(false);
            CommonFun.DelayCallback(() =>
            {
                scoreFinishBg.localPosition = defaultScoreBgPos;
                scoreFinishBg.gameObject.SetActive(true);
                scoreFinishBg.DOLocalMoveY(defaultScoreBgPos.y + 300, 1F).OnComplete(() =>
                {
                    scoreFinishBg.gameObject.SetActive(false);
                    this.scoreFinishTipsTran.SetActive(false);
                    this.gameObject.SetActive(false);
                });
            },0.2F).Forget();
        }

        public  void ShowBuildFinish()
        {
           this.buildFinishTipsTran.SetActive(true);
           this.scoreFinishTipsTran.SetActive(false);
           buildFinishNumTxt.text = string.Format("盖至{0}层", DataManager.Instance.BuildCityIdList.Count);

           buildFinishBg.localPosition = defaultScoreBgPos;
           buildFinishBg.gameObject.SetActive(true);
           
           Sequence sq = DOTween.Sequence();

           sq.Append(buildFinishBg.DOLocalMoveY(defaultScoreBgPos.y + 300, 1F));
           // sq.AppendCallback(() =>
           // {
           //     buildIcon.SetParent(this.buildFinishTipsTran.transform);
           // });
           // sq.Append(buildIcon.DOMove(pos, 0.5F));
           // sq.Join(buildIcon.DOScale(new Vector3(0.2F, 0.2F, 0.2F), 0.8F));
           sq.OnComplete(() =>
           {
               // buildIcon.SetParent(buildFinishBg);
               // buildIcon.localPosition = new Vector3(-255, 11, 0);
               buildFinishBg.gameObject.SetActive(false);
               this.buildFinishTipsTran.SetActive(false);
               this.gameObject.SetActive(false);
           });
   
        }
    }
}